<?php

include_once APPLICATION_DIR . "/application/model/PARAMETER.php";
class Parameter extends DataObjects_PARAMETER
{
	function saveValue($id_param,$value, $label=NULL)
	{
		if ($this->canViewForm())
		{
			$this->get($id_param);
			if ($this->VALUE != $value)
			{
				$this->VALUE = $value;
				$this->LABEL = $label;
				return $this->update();
			}
		}
		return false;
	}

	/*
	* Load and define constants from table PARAMETER
	*/
	public static function loadConstants()
	{
		$param = new Parameter();
		$param->find();
		while ($param->fetch())
		{
			if (defined($param->NOM))
				unset($param->NOM);

			define($param->NOM,$param->VALUE);
		}
	}

	/** check whether the current login user can view the emplacement form
	* @return bool
	*/
	function canViewForm()
	{
		if ($_SESSION["userClasse"] == "user_regie")
		{
			return false;
		}
		return true;
	}
    public static function getErrorDescription($code = 0, $type_name="")
    {
       switch($code)
        {
            case 501: //empty
                return $type_name.CHK_ERR_PARAMETER_EMPTY;
            case 502: //not type
                return CHK_ERR_PARAMETER_NOT_TYPE.$type_name;
            case 503: //not exist
                return $type_name.CHK_ERR_PARAMETER_NOT_EXIST;
            case 504: //invalid
                return $type_name.CHK_ERR_PARAMETER_INVALID;
            case 505: //type invalid
                return $type_name.CHK_ERR_PARAMETER_TYPE_INVALID;
            case 506: //name space
                return $type_name.CHK_ERR_PARAMETER_NAME_SPACE;
            case 507: //decimal
                return $type_name.CHK_ERR_PARAMETER_INVALID_DECIMAL;
            case 508: //length
                return $type_name.CHK_ERR_PARAMETER_LENGTH;
            case 509: //min length
                return $type_name.CHK_ERR_PARAMETER_MIN_LENGTH;
            case 510: //max length
                return $type_name.CHK_ERR_PARAMETER_MAX_LENGTH;
            case 511: //width
                return $type_name.CHK_ERR_PARAMETER_WIDTH;
            case 512: //min-width
                return $type_name.CHK_ERR_PARAMETER_MIN_WIDTH;
            case 513: //max width
                return $type_name.CHK_ERR_PARAMETER_MAX_WIDTH;
            case 514: //heigth
                return $type_name.CHK_ERR_PARAMETER_HEIGTH;
            case 515: //min-heigth
                return $type_name.CHK_ERR_PARAMETER_MIN_HEIGTH;
            case 516: //max-height
                return $type_name.CHK_ERR_PARAMETER_MAX_HEIGTH;
            case 517: //min value
                return $type_name.CHK_ERR_PARAMETER_MIN;
            case 518: //max value
                return $type_name.CHK_ERR_PARAMETER_MAX;
            case 519: //size
                return $type_name.CHK_ERR_PARAMETER_SIZE;
            case 520: //min size
                return $type_name.CHK_ERR_PARAMETER_MIN_SIZE;
            case 521: //max size
                return $type_name.CHK_ERR_PARAMETER_MAX_SIZE;
            default :
                return CHK_ERR_PARAMETER_ERROR_UNDEFINED;
        }
    }
}